// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-11

package responses

import (
	"gitee.com/go-libs/db-xorm/db"
	"server/app/http/models"
	"server/app/kind"
)

// TicketSessionResponse
// 渔票场次信息.
type TicketSessionResponse struct {
	Id        int64             `label:"场次ID"`
	ArcadeId  kind.ArcadeId     `label:"钓场ID"`
	TicketId  int64             `label:"渔票ID"`
	Date      db.Date           `label:"作钓日期"`
	DateKey   int               `label:"场次编号"`
	State     kind.SessionState `label:"状态位"`
	StateFlag string            `label:"状态标识"`
	StateText string            `label:"状态值"`

	Price            kind.Balance            `label:"售价"`
	Hours            float64                 `label:"作钓时长"`
	Time             kind.TicketTime         `label:"作钓时段"`
	TimeText         string                  `label:"作钓时段名"`
	TimeStart        string                  `label:"开始时间"`
	TimeEnd          string                  `label:"截止时间"`
	Seat             kind.PondSeat           `label:"钓位类型"`
	SeatText         string                  `label:"钓位类型名"`
	SeatStrategy     kind.TicketSeatStrategy `label:"钓位策略"`
	SeatStrategyText string                  `label:"钓位策略名"`

	OrderTotal  int `label:"订单总数"`
	OrderCount  int `label:"订单数"`
	RefundCount int `label:"退单数"`
	LockedCount int `label:"锁定数"`

	ReturnMode      kind.ReturnMode
	ReturnModeText  string
	ReturnPrice     float64
	ReturnMinAmount kind.Balance

	CanBuy       bool
	IsDrawLot    bool
	IsUserChoose bool

	Goods  []*TicketFreeGoodsResponse `json:",omitempty"`
	Ticket *TicketResponse            `json:",omitempty"`
}

// AddGoodsResponse
// 添加商品.
func (o *TicketSessionResponse) AddGoodsResponse(gs ...*TicketFreeGoodsResponse) {
	if o.Goods == nil {
		o.Goods = make([]*TicketFreeGoodsResponse, 0)
	}
	o.Goods = append(o.Goods, gs...)
}

// With
// 数据绑定.
func (o *TicketSessionResponse) With(m *models.TicketSession) *TicketSessionResponse {
	o.Id = m.Id
	o.ArcadeId = m.ArcadeId
	o.TicketId = m.TicketId
	o.Date = m.Date
	o.DateKey = m.DateKey
	o.State = m.State
	o.StateFlag = m.State.Flag()
	o.StateText = m.State.Text()
	o.Price = m.Price
	o.Hours = m.Hours
	o.Time = m.Time
	o.TimeText = m.Time.Text()
	o.TimeStart = m.TimeStart
	o.TimeEnd = m.TimeEnd
	o.Seat = m.Seat
	o.SeatText = m.Seat.Text()
	o.SeatStrategy = m.SeatStrategy
	o.SeatStrategyText = m.SeatStrategy.Text()
	o.OrderTotal = m.OrderTotal
	o.OrderCount = m.OrderCount
	o.RefundCount = m.RefundCount
	o.LockedCount = m.LockedCount

	o.ReturnMode = m.ReturnMode
	o.ReturnModeText = m.ReturnMode.Text()
	o.ReturnPrice = m.ReturnPrice
	o.ReturnMinAmount = m.ReturnMinAmount

	o.IsDrawLot = m.SeatStrategy.IsDrawLot()
	o.IsUserChoose = m.SeatStrategy.IsUserChoose()
	return o
}

// WithTicket
// 绑定渔票.
func (o *TicketSessionResponse) WithTicket(m *models.Ticket) *TicketSessionResponse {
	if m != nil {
		o.Ticket = (&TicketResponse{}).With(m)
	}
	return o
}
